package com.person.monitor;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class LogListAdapter extends BaseAdapter {

    Context context;

    List<String> logList = new ArrayList<>();
    LayoutInflater layoutInflater;

    public LogListAdapter(Context context){
        this.context = context;

        layoutInflater = LayoutInflater.from(context);
    }

    public void setLogList(List<String> list){
        logList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return logList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView == null){
            convertView = layoutInflater.inflate(R.layout.list_item_log,parent,false);
        }

        TextView logText = convertView.findViewById(R.id.list_item_log_text);

        logText.setText(logList.get(position));

        return convertView;
    }
}
